home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / swapqpu.zip / SWAPUNIT.DOC < prev    next >
Text File  |  1992-03-14  |  17KB  |  352 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                        SWAPUNIT: Swap and Execute Unit
  7.  
  8.                          Copyright 1992  Kevin Kwast
  9.  
  10.  
  11.                                March 14, 1992
  12.  
  13.  
  14.  
  15.  
  16.               SWAPUNIT allows you to execute a program (like the Turbo
  17.         Pascal Exec procedure) with the maximum of available memory. Just
  18.         add SWAPUNIT to Uses clause and use SwapExec instead of the
  19.         standard Exec.  Memory previously used by your program will be
  20.         swapped to XMS, EMS, or the hard disk, freeing up more available
  21.         memory for the executed program or DOS shell.
  22.  
  23.               SWAPUNIT requires Turbo Pascal version 4 or above or any
  24.         version of Microsoft Pascal.  Units are included which were made
  25.         under Turbo Pascal versions 4.0, 5.5, and 6.0 and QuickPascal
  26.         version 1.0 for your convenience.  The Turbo Pascal units are
  27.         named SWAPUNIT.TP4 and so on; rename your choice to SWAPUNIT.TPU
  28.         and use it.
  29.  
  30.               The results can be astounding, particularly with programs
  31.         that use a lot of stack or heap space.  The SwapExec procedure
  32.         is hand-coded in assembly language for optimal speed and minimum
  33.         overhead.  A child program or DOS shell can be spawned with as
  34.         little as 3K overhead.  Sound unbelievable? Try it!  You have 30
  35.         days to examine SWAPUNIT and see if it meets your needs; if you
  36.         decide to use SWAPUNIT, please register your usage with the
  37.         author.  See the end of this documentation for information.
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.               Here is the interface section of SWAPUNIT, which includes
  45.         comments describing the unit's usage and results:
  46.  
  47.         Unit SwapUnit;                  { Kevin A. Kwast }
  48.         (**********************************************************************)
  49.         (** This unit provides your programs with the ability to swap out    **)
  50.         (** its memory blocks to XMS, EMS, or the hard disk (in that order)  **)
  51.         (** and EXEC another program.  Put this unit last in the Uses list   **)
  52.         (** for best performance (Pascal always links in reverse).  The Try  **)
  53.         (** parameter allows the caller to specify which methods of swapping **)
  54.         (** will be attempted.  They are additive, so SwapToEMS+SwapToXMS    **)
  55.         (** will try swapping to EMS and XMS, but not to the disk.  The word **)
  56.         (** result of the SwapExec function is the result code, with the Hi  **)
  57.         (** and Lo bytes having the following meanings:                      **)
  58.         (**                                                                  **)
  59.         (**  Hi(Result) = 0:   Success, the swapping and execution was OK.   **)
  60.         (**                     The DOS errorlevel result is in Lo(Result).  **)
  61.         (**             = 1:   An error in the DOS memory chain prevented    **)
  62.         (**                     swapping.  This is unlikely.                 **)
  63.         (**             = 2:   Unable to swap the program to any of the      **)
  64.         (**                     methods allowed.                             **)
  65.         (**             = 3:   Swapping was alright, but the program name    **)
  66.         (**                     specified could not be executed.  The low    **)
  67.         (**                     byte describes the execution problem.        **)
  68.         (**                                                                  **)
  69.         (**  Lo(Result) = 2:   Program name could not be found to execute.   **)
  70.         (**             = 5:   Couldn't open the program name.               **)
  71.         (**             = 8:   Insufficient memory to run the program.       **)
  72.         (**                                                                  **)
  73.         (**********************************************************************)
  74.  
  75.         Interface
  76.  
  77.           Const
  78.               SwapToDisk = 4;
  79.               SwapToEMS = 2;
  80.               SwapToXMS = 1;
  81.               SwapToAny = 7;
  82.  
  83.           Function SwapExec(Program_Name, Command_Line, Swap_FName: String;
  84.                             Try: Byte) : Word;
  85.  
  86.           Function CheckEMS : Boolean;
  87.           Function CheckXMS : Boolean;
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.         -------------------
  95.         Function  SwapExec
  96.         -------------------
  97.           Parameter:  Program_Name     This is a Pascal string of any type
  98.                                        containing the program which will be
  99.                                        executed.  This string is a DOS file
  100.                                        specification which MUST include a
  101.                                        file name and extension, and may
  102.                                        include a drive and path.  Any drive
  103.                                        accessible by DOS is valid here.
  104.  
  105.           Parameter:  Command_Line     This command line will be passed to
  106.                                        the executed program.
  107.  
  108.           Parameter:  Swap_FName       This is a DOS file specification to
  109.                                        be used if it is necessary to swap
  110.                                        to disk.  This should be specified
  111.                                        if SwapExec will try to swap to disk.
  112.  
  113.           Parameter:  Try              This byte describes which storage
  114.                                        forms will be attempted in swapping.
  115.                                        The constants SwapToXMS, SwapToEMS,
  116.                                        SwapToDisk, and SwapToAny have been
  117.                                        provided for user convenience.
  118.  
  119.           Result                       The word returned by the function
  120.                                        describes the results of the swap
  121.                                        and program execution.  Check the
  122.                                        high and low bytes for individual
  123.                                        status codes documented above.
  124.  
  125.         -------------------
  126.         Function  CheckEMS
  127.         -------------------
  128.  
  129.           Result                       The boolean result returns TRUE if
  130.                                        LIM EMS 4.0 or compatible expanded
  131.                                        memory is available.  This is the
  132.                                        form of expanded memory required
  133.                                        in order to swap to EMS.
  134.  
  135.         -------------------
  136.         Function  CheckXMS
  137.         -------------------
  138.  
  139.           Result                       The boolean result returns TRUE if
  140.                                        a Microsoft XMS or compatible driver
  141.                                        provides extended memory support.
  142.                                        A driver like this is necessary to
  143.                                        provide XMS support to SWAPUNIT.
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.               In order to get the optimum performance from SWAPUNIT, you
  151.         need to understand how SWAPUNIT works, how Pascal allocates
  152.         memory, and how you can use these memory allocation characteristics
  153.         to your advantage.
  154.  
  155.               First of all, program memory is allocated as one large block
  156.         including the program code, unit code, data, stack, and heap space.
  157.         SWAPUNIT can save everything after itself in the memory block to
  158.         XMS, EMS, or the hard disk.  SwapExec will try XMS, then EMS, and
  159.         then try to save to disk (you can allow swapping to only some of
  160.         those forms with the Try parameter).  If swapping is successful,
  161.         the memory block is reduced in size and the child program is
  162.         executed.  After the child program returns, SWAPUNIT (which was
  163.         not swapped out) will reload the rest of the memory block and
  164.         restore the DOS memory block to its former status.  Graphically,
  165.         an example program being swapped looks like this:
  166.  
  167.           Before calling SwapExec:       After SWAPUNIT Swaps:       
  168.  
  169.             -------------------           -------------------
  170.             / 40K Free Memory \           /                 \
  171.             |=================|           /  All Of This Is \
  172.             | 500K Heap       |           /   Swapped Out   \
  173.             |=================|           /  And Available! \
  174.             | 16K Stack       |           /                 \
  175.             |=================|           /   574K Free     \
  176.             | 10K Data        |           /    Memory!      \
  177.             |=================|           |=================|
  178.             | 10K Units Code  |           | 2K SWAPUNIT     |
  179.             |=================|           |=================|
  180.             | 5K Program Code |           | 5K Program Code |
  181.             -------------------           -------------------
  182.  
  183.  
  184.               Since SWAPUNIT can only swap out what appears after itself
  185.         in memory, you want SWAPUNIT to be the first unit in memory, and
  186.         you want the program code (all the code in the main Pascal file)
  187.         segment to be as small as possible.  For those using Turbo Pascal
  188.         version 5 or above, compile your program with map file generation
  189.         (this is the /GS parameter in TPC, the command line compiler).
  190.         Take a look at the .MAP file to see how memory will be used by
  191.         the compiled program.  You will see your program's name appearing
  192.         as the first area in the .MAP file, with areas appearing later
  193.         (or higher) in memory further on in the MAP file.  Note that the
  194.         SYSTEM unit (which is always includes) is automatically linked
  195.         as the last unit in memory; this is not a concern.
  196.  
  197.               SwapExec will swap out everything after the SWAPUNIT area
  198.         and restore it when SwapExec returns.  Pascal will always put
  199.         the data, stack, and heap where they can be swapped out, but
  200.         maximizing the unit and program code space which can be swapped
  201.         out requires a little inside knowledge.
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.               Thus, your goal is to have a small main program area with
  209.         SWAPUNIT immediately after that.  Here are a few tips and facts
  210.         to make this feat easier to accomplish:
  211.  
  212.         *  String constants will be in the code segment.  This means that
  213.            if your main program contains a great deal of literal strings
  214.            [such as things like: WriteLn('Hello there.');], your code
  215.            segment can get very large.  The best solution to this problem
  216.            is declaring your strings in the Const section (which are
  217.            allocated in the data segment) and then use the constant.
  218.            [For example: Const Str1 = 'Hello there.'; WriteLn(Str1);]
  219.            You will see this technique in the SWAPTEST example program.
  220.  
  221.         *  Each unit occupies its own segment.  These are linked in the
  222.            reverse order of their appearance on the Uses line, so that
  223.            the last unit on the line will be the earliest in memory.
  224.  
  225.         *  The program's memory block will be loaded in order (from first
  226.            to last in memory):  the main program code, the unit segments
  227.            (where each unit has its own code and data), the main program
  228.            data, the stack, and the heap.
  229.  
  230.         *  In order to keep the main program code as small as possible
  231.            (since this is unavoidable overhead), put as much as you can
  232.            in seperate units.  With the SWAPUNIT source code, you will
  233.            have more flexibility in usage.
  234.  
  235.  
  236.         See the enclosed SWAPTEST example Turbo Pascal program and the
  237.         commented SWAPTEST.MAP file (produced by Turbo Pascal 6.0) for
  238.         an example of SwapExec usage and results.
  239.  
  240.         Please note that the SwapExec "swap to disk" function requires
  241.         the user to have at least DOS 3.0, while everything else needs
  242.         DOS 2.0 (as does anything, really).  If the user doesn't have
  243.         DOS 3.0 or above, swapping to disk will automatically fail.
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.         -----------------------------------------------------------------
  251.                                D I S C L A I M E R
  252.         -----------------------------------------------------------------
  253.  
  254.           Every effort has been made to insure that SWAPUNIT works as
  255.           described, and runs completely error-free.  No guarantee is
  256.           made as to the suitability of SWAPUNIT to any purpose, and I
  257.           cannot be responsible for any damages alledged to have been
  258.           caused by the use of SWAPUNIT.  If you find a problem with
  259.           the usage of SWAPUNIT, please alert the author at the address
  260.           below.  SWAPUNIT will continue to go through testing and
  261.           modification to ensure the best possible product.
  262.  
  263.  
  264.         -----------------------------------------------------------------
  265.                        A B O U T   T H I S   P R O G R A M
  266.         -----------------------------------------------------------------
  267.  
  268.           SWAPUNIT is Copyright 1992 by Kevin A. Kwast, and protected
  269.           by copyright laws under U.S. and International law.  The user
  270.           is granted the right to copy and distribute this package in
  271.           its complete, unaltered form.  Usage of SWAPUNIT requires a
  272.           Shareware registration fee be paid to the author.  In this
  273.           way, you can examine SWAPUNIT and see if it meets your needs
  274.           before you purchase the program.  Take it for a spin; drive
  275.           it around the block a few times.  Try it out for 30 days, but
  276.           please note that you may not use beyond this time (or use it
  277.           in any program) until you register your usage.  When you do,
  278.           you will receive the Pascal source code to SWAPUNIT (but not
  279.           the assembly language source to the SwapExec routine), so you
  280.           can remove the registration notice from the start of the unit
  281.           and create a more specialized unit in order to eliminate
  282.           overhead.  Specify disk type when you register, and you will
  283.           receive the source code and additional examples so that you
  284.           can begin producing the best programs possible.
  285.  
  286.           Thank you in advance for your support of Shareware products.
  287.           Months of effort were put into this product, and your support
  288.           shows that you appreciate products like these.  Is $35 worth
  289.           the effort you would put into designing something like this
  290.           yourself?  You can use the form on the next page (which is
  291.           also found in the file REGISTER.ME) -- Thank you again!
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.         -----------------------------------------------------------------
  299.                         R E G I S T R A T I O N   F O R M
  300.         -----------------------------------------------------------------
  301.  
  302.          Print and complete this form to send with check or money order
  303.          in the amount of $35 (US dollars only) payable to KEVIN KWAST.
  304.          Mail to the address below, and thank you for your support; your
  305.          registration makes quality Shareware possible.  You will
  306.          receive the latest SWAPUNIT package including source code.
  307.  
  308.  
  309.          Any of this information is optional.
  310.  
  311.  
  312.            Name: ____________________________________________________
  313.  
  314.            Company: _________________________________________________
  315.  
  316.            Address: _________________________________________________
  317.  
  318.            City: ____________________  State: _______  Zip: _________
  319.  
  320.            Area Code: _________  Phone: _____________________________
  321.  
  322.  
  323.  
  324.            Circle:    *Turbo Pascal*      *Microsoft Pascal*
  325.  
  326.            Version: ___________________  Do You Use a Modem? ________
  327.  
  328.            Other Languages You Use: _________________________________
  329.  
  330.            Computer Type: ___________________________________________
  331.  
  332.            Disk Size Preferred:   [___] 5.25 inch     [____] 3.5 inch
  333.  
  334.  
  335.  
  336.            Where Did You Get SWAPUNIT: ______________________________
  337.  
  338.            What Do You Think: _______________________________________
  339.  
  340.            What Will It Be Used For: ________________________________
  341.  
  342.  
  343.  
  344.  
  345.          You can contact me for registration or support:
  346.  
  347.                       Kevin A. Kwast
  348.                       P. O. Box 1397
  349.                       Coppell, Texas
  350.                               75019
  351.  
  352.